﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{
    //
    public class JLTAB55DOCData : BaseFunction
    {
        ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        SETINTEXDB INTEXDB = new SETINTEXDB();
        public JLTAB55DOCData()
            : base()
        {

        }
        public JLTAB55DOCData(OracleConnection _OracleDB, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_OracleDB, _proxy, userID)
        {
        }
        public JLTAB55DOCData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {

        }
        public DataSet BuildData(DataRow dwInput)
        {
            DataSet Result = new DataSet();
            DataSet Return = new DataSet();
            DataRow dwData = null;
            DataRow dwABP = null;
            try
            {
                //ABKOPF;ABPOS;ABPR;ABFOLGE;BSSATZ;BHSATZ;BASTGA;GAAUF;BAAUF;BABST;
                #region===AB============
                dwData = INTEXDB.ABKOPF.NewRow();
                dwData["ABKMANDANT"] = dwInput["ABPMANDANT"];
                dwData["ABKAUFKRS"] = dwInput["ABPAUFKRS"];
                dwData["ABKAUFLFD"] = dwInput["ABPAUFLFD"];
                Result = INTEXDBC.QueryABKOPF(dwData);
                Return.Merge(Result);

                dwData = INTEXDB.ABPOS.NewRow();
                dwData["ABPMANDANT"] = dwInput["ABPMANDANT"];
                dwData["ABPAUFKRS"] = dwInput["ABPAUFKRS"];
                dwData["ABPAUFLFD"] = dwInput["ABPAUFLFD"];
                dwData["ABPAUFPOS"] = dwInput["ABPAUFPOS"];
                Result = INTEXDBC.QueryABPOS(dwData, 1);
                foreach (DataRow row in Result.Tables[0].Rows)
                {
                    dwABP = row;
                }
                if (dwABP == null)
                    throw new Exception(" 没有找到");
                string order = "";
                string remark = "";
                order = dwABP["ABPAUFKRS"].ToString() + dwABP["ABPAUFLFD"].ToString() + "   ";
                remark += GetCommentsFromTXTIND("AB3", order).Trim();
                order = dwABP["ABPAUFKRS"].ToString() + dwABP["ABPAUFLFD"].ToString() + dwABP["ABPAUFPOS"].ToString();
                remark += GetCommentsFromTXTIND("ABP", order).Trim();
                dwABP["ABPFILLER1"] = remark;
                Return.Merge(Result);       

                dwData = INTEXDB.ABFOLGE.NewRow();
                dwData["ABFMANDANT"] = dwABP["ABPMANDANT"];
                dwData["ABFAUFKRS"] = dwABP["ABPAUFKRS"];
                dwData["ABFAUFLFD"] = dwABP["ABPAUFLFD"];
                dwData["ABFAUFPOS"] = dwABP["ABPAUFPOS"];
                Result = INTEXDBC.QueryABFOLGE(dwData, 1);
                Return.Merge(Result);

                #endregion
                #region===Master=======
                dwData = INTEXDB.WASTAMM.NewRow();
                dwData["WAMANDANT"] = dwABP["ABPMANDANT"];
                dwData["WAART"] = dwABP["ABPART"];
                Result = INTEXDBC.QueryWASTAMM(dwData, 3);
                Return.Merge(Result);
                #endregion
                #region===Material=======
                dwData = INTEXDB.WASTGA.NewRow();
                dwData["WAGMANDANT"] = dwABP["ABPMANDANT"];
                dwData["WAGART"] = dwABP["ABPART"];
                dwData["WAGVAR"] = Left(dwABP["ABPVAR"].ToString(), 2);
                dwData["WAGWCOL"] = dwABP["ABPFARBE"];
                Result = INTEXDBC.QueryWASTGA(dwData, 2);
                Return.Merge(Result);
                dwData = INTEXDB.GAAUF.NewRow();
                dwData["GAMANDANT"] = dwABP["ABPMANDANT"];
                dwData["GAAUFKRS"] = dwABP["ABPAUFKRS"];
                dwData["GAAUFLFD"] = dwABP["ABPAUFLFD"];
                dwData["GAAUFPOS"] = dwABP["ABPAUFPOS"];
                Result = INTEXDBC.QueryGAAUF(dwData, 2);
                Return.Merge(Result);

                dwData = INTEXDB.BABST.NewRow();
                dwData["BMMANDANT"] = dwABP["ABPMANDANT"];
                dwData["BMAUFKRS"] = dwABP["ABPAUFKRS"];
                dwData["BMAUFLFD"] = dwABP["ABPAUFLFD"];
                dwData["BMAUFPOS"] = dwABP["ABPAUFPOS"];
                Result = INTEXDBC.QueryBABST(dwData, 5);
                Return.Merge(Result);
                dwData = INTEXDB.BABST.NewRow();
                dwData["BMMANDANT"] = dwABP["ABPMANDANT"];
                dwData["BMKART"] = dwABP["ABPART"];
                dwData["BMKVAR"] = "1 ";
                dwData["BMFARBE"] = dwABP["ABPFARBE"];
                Result = INTEXDBC.QueryBABST(dwData, 4);
                Result.Tables[0].TableName = "TBABST";
                Return.Merge(Result);
                #endregion
                #region=====stock==========
                dwData = INTEXDB.WBBST.NewRow();
                dwData["WBBMANDANT"] = dwABP["ABPMANDANT"];
                dwData["WBBAUFKRS"] = dwABP["ABPAUFKRS"];
                dwData["WBBAUFLFD"] = dwABP["ABPAUFLFD"];
                dwData["WBBAUFPOS"] = dwABP["ABPAUFPOS"];
                Result = INTEXDBC.QueryWBBST(dwData, 8);
                Return.Merge(Result); 
                #endregion 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        public DataSet QueryAB50(DataRow dwInput)
        {
            DataSet Result = new DataSet();
            DataSet Return = new DataSet();
            DataRow dwData = null;
            DataRow dwABP = null;
            DataRow dwABK = null;
            try
            {
                //ABKOPF;ABPOS;ABPR;ABFOLGE;BSSATZ;BHSATZ;BASTGA;GAAUF;BAAUF;BABST;
                #region===AB============
                dwData = INTEXDB.ABKOPF.NewRow();
                dwData["ABKMANDANT"] = dwInput["ABPMANDANT"];
                dwData["ABKAUFKRS"] = dwInput["ABPAUFKRS"];
                dwData["ABKAUFLFD"] = dwInput["ABPAUFLFD"];
                Result = INTEXDBC.QueryABKOPF(dwData);
                Return.Merge(Result);
                foreach (DataRow row in Return.Tables["ABKOPF"].Rows)
                {
                    dwABK = row;
                }
                dwData = INTEXDB.ABPOS.NewRow();
                dwData["ABPMANDANT"] = dwInput["ABPMANDANT"];
                dwData["ABPAUFKRS"] = dwInput["ABPAUFKRS"];
                dwData["ABPAUFLFD"] = dwInput["ABPAUFLFD"];
                Result = INTEXDBC.QueryABPOS(dwData, 2);
                foreach (DataRow row in Result.Tables[0].Rows)
                {
                    dwABP = row;
                }
                if (dwABP == null)
                    throw new Exception(" 没有找到");
                string order = "";
                string remark = "";
                order = dwABP["ABPAUFKRS"].ToString() + dwABP["ABPAUFLFD"].ToString() + "   ";
                remark += GetCommentsFromTXTIND("AB3", order).Trim();
                order = dwABP["ABPAUFKRS"].ToString() + dwABP["ABPAUFLFD"].ToString() + dwABP["ABPAUFPOS"].ToString();
                remark += GetCommentsFromTXTIND("ABP", order).Trim();
                dwABP["ABPFILLER1"] = remark;
                Return.Merge(Result);
                #endregion
                #region===Master=======
                dwData = INTEXDB.WASTAMM.NewRow();
                dwData["WAMANDANT"] = dwABK["ABKMANDANT"];
                dwData["WAART"] = Left(dwABK["ABKKDAUFTNR"].ToString(), 6);
                Result = INTEXDBC.QueryWASTAMM(dwData, 3);
                Return.Merge(Result);
                #endregion
                #region===Material=======
                dwData = INTEXDB.WASTGA.NewRow();
                dwData["WAGMANDANT"] = dwABK["ABKMANDANT"];
                dwData["WAGART"] = Left(dwABK["ABKKDAUFTNR"].ToString(), 6);
                dwData["WAGVAR"] = "  ";
                dwData["WAGWCOL"] = dwABK["ABKKDAUFTNR"].ToString().Substring(7, 10);
                Result = INTEXDBC.QueryWASTGA(dwData, 2);
                Return.Merge(Result);
                dwData = INTEXDB.GAAUF.NewRow();
                dwData["GAMANDANT"] = dwABP["ABPMANDANT"];
                dwData["GAAUFKRS"] = dwABP["ABPAUFKRS"];
                dwData["GAAUFLFD"] = dwABP["ABPAUFLFD"];
                Result = INTEXDBC.QueryGAAUF(dwData, 6);
                Return.Merge(Result);
                #endregion
                #region=====stock==========
                dwData = INTEXDB.ZUTEI.NewRow();
                dwData["ZUMANDANT"] = dwABP["ABPMANDANT"];
                dwData["ZUAUFKRS"] = dwABP["ABPAUFKRS"];
                dwData["ZUAUFLFD"] = dwABP["ABPAUFLFD"];
                Result = INTEXDBC.QueryZUTEI(dwData, 4);
                Return.Merge(Result);
                #endregion 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }

    }
}